package homework;

import java.util.Scanner;

public class homework2 {
    public static void main(String[] args) {
        //统计一个数在内存中以二进制存储的1的个数
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数：");
        int a = sc.nextInt();
        int count = 0;
        while(a!=0){
            count++;
            a=a&(a-1);
        }
        System.out.println(count);
    }
    public static void main3(String[] args) {
        //求两个数的最大公约数
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入两个数：");
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = a%b;
        while(c!=0){
            a=b;
            b=c;
            c=a%b;
        }
        System.out.println("最大公约数为："+b);
    }
    public static void main2(String[] args) {
        //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
        double sum = 0;
        for (int i = 1; i <=100 ; i++) {
            sum=sum+(1.0/i)*Math.pow((-1),(i-1));
        }
        System.out.println(sum);
    }
    public static void main1(String[] args) {
        //输出三位数的水仙花数
        for(int i=100;i<=999;i++){
            int a = i%10;
            int b = (i%100)/10;
            int c = i/100;
            if(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)==i){
                System.out.println(i);
            }
        }
    }
}
